package com.heima.user.controller;

import com.heima.common.constants.ApUserConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.user.dto.AuthDto;
import com.heima.model.user.entity.ApUserRealname;
import com.heima.user.service.ApUserRealnameService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * APP实名认证信息表(ApUserRealname)表控制层
 *
 * @author makejava
 * @since 2022-04-29 21:48:16
 */
@RestController
@RequestMapping(path = "/api/v1/auth")
public class ApUserRealnameController {
    /**
     * 服务对象
     */
    @Resource
    private ApUserRealnameService apUserRealnameService;


    /**
     * 提交用户实名认证信息
     * 参数名=参数值&参数名=参数值&参数名=参数值
     *
     * @return
     */
    @PostMapping(path = "/submit")
    public ResponseResult submit(MultipartFile font_image,
                                 MultipartFile back_image,
                                 MultipartFile hold_image,
                                 MultipartFile live_image,
                                 String name,
                                 String idno) {

        return apUserRealnameService.submit(font_image, back_image, hold_image, live_image, name, idno);
    }

    /**
     * 查询实名认证列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult loadListByStatus(@RequestBody AuthDto dto) {
        return apUserRealnameService.loadListByStatus(dto);
    }


    /**
     * 用户身份信息审核通过
     * @param dto
     * @return
     */
    @PostMapping("/authPass")
    public ResponseResult authPass(@RequestBody AuthDto dto) {
        return apUserRealnameService.updateStatus(dto, ApUserConstants.PASS_AUTH);
    }

    /**
     * 用户身份信息审核不通过
     * @param dto
     * @return
     */
    @PostMapping("/authFail")
    public ResponseResult authFail(@RequestBody AuthDto dto) {
        return apUserRealnameService.updateStatus(dto, ApUserConstants.FAIL_AUTH);
    }


    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<ApUserRealname> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.apUserRealnameService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param apUserRealname 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ApUserRealname> add(ApUserRealname apUserRealname) {
        return ResponseEntity.ok(this.apUserRealnameService.insert(apUserRealname));
    }

    /**
     * 编辑数据
     *
     * @param apUserRealname 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ApUserRealname> edit(ApUserRealname apUserRealname) {
        return ResponseEntity.ok(this.apUserRealnameService.update(apUserRealname));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.apUserRealnameService.deleteById(id));
    }


}

